//
//  HomePageContentDetailCell.m
//  ShowYork
//
//  Created by hxh on 2020/10/4.
//  Copyright © 2020 hxh. All rights reserved.
//

#define TOOLHEIGHT 46.0f
#define TAGHEIGHT 34.0f
#define HEADERHEIGHT 74.0f
#import "HomePageContentDetailCell.h"
#import "XHPageControl.h"
@interface HomePageContentDetailCell ()<XHPageControlDelegate,UIScrollViewDelegate>
@property (nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UILabel *textLb;
//@property (nonatomic,strong)XHPageControl *page;
@property (nonatomic,strong)UIView *footerView;
@property (nonatomic,strong)UIView *toolView;
@property (nonatomic,strong)UILabel *dissCount;
@property (nonatomic,strong)UILabel *likeCount;
@property (nonatomic,strong)UILabel *commentCount;
@property (nonatomic,strong)UIImageView *dissIcon;
@property (nonatomic,strong)UIImageView *likeIcon;
@property (nonatomic,strong)UIImageView *headerIcon;
@property (nonatomic,strong)UIImageView *commentIcon;
@property (nonatomic,strong)UIButton *followBtn;
@property (nonatomic,strong)UILabel *nameLb;
@property (nonatomic,strong)UIButton *coverBtn;
@property (nonatomic,strong)CAGradientLayer *gradientLayer;


@property (nonatomic,strong)HomePageItemModel *currentModel;

@property (nonatomic,strong)UIButton *commentBtn;
@property (nonatomic,strong)UIButton *dissBtn;
@property (nonatomic,strong)UIButton *likeBtn;

@property (nonatomic,strong)UILabel *tagLb;
@property (nonatomic,strong)UIView *tagView;
@property (nonatomic,strong)UIImageView *tagImageView;

@property (nonatomic,assign)CGFloat maxHeight;

@property (nonatomic,strong)UILabel *subTitleLb;
@property (nonatomic,strong)UIView *longPressFooterView;
@end


@implementation HomePageContentDetailCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];

    }
    return self;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{

    
    // 头像占用的大小
    
//    24 + 38 + 12
    
    // 标签占用大小
    // 22 + 12
    
    // 底部工具条
    // 12 + 16 + 18
    
    // 底部安全区域
    
    self.backgroundColor = [UIColor blackColor];
    
    self.coverBtn = [[UIButton alloc]init];
    [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;

    [self.contentView addSubview:self.scrollView];
    
    self.scrollView.pagingEnabled = YES;

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(coverMethod)];
    [self.scrollView addGestureRecognizer:tap];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.right.equalTo(self.contentView).offset(-16);
        make.top.equalTo(self.contentView).offset(kNavBarHeight + 16.0);
        make.bottom.mas_equalTo(self.contentView).offset(-(110 + GK_SAVEAREA_BTM));
    }];
   
    UIView *lastView = nil;
    for (int i = 0; i< 5; i++) {
        UILabel *lb = [[UILabel alloc]init];
        lb.numberOfLines = 0;
        lb.font = [UIFont fontWithName:@"PingFang SC" size:14];
        lb.textColor = [UIColor whiteColor];
        [self.scrollView addSubview:lb];
        if (lastView == nil) {
            [lb mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.width.equalTo(self.scrollView);
                make.leading.mas_equalTo(self.scrollView.mas_leading);
            }];
        }else{
            [lb mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.width.equalTo(self.scrollView);
                make.leading.mas_equalTo(lastView.mas_trailing);
            }];
        }
        lastView = lb;
    }
    
    self.longPressFooterView = [[UIView alloc]init];
    [self.contentView addSubview:self.longPressFooterView];
    
    self.footerView = [[UIView alloc]init];
    [self.contentView addSubview:self.footerView];
    [self.footerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(TOOLHEIGHT + TAGHEIGHT + HEADERHEIGHT + GK_SAVEAREA_BTM);
    }];
    
    self.toolView = [[UIView alloc]init];
    [self.footerView addSubview:self.toolView];
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.footerView).offset(-GK_SAVEAREA_BTM);
        make.left.right.equalTo(self.footerView);
        make.height.mas_equalTo(TOOLHEIGHT);
    }];
    
    self.likeCount = [[UILabel alloc]init];
    self.likeCount.textColor = [UIColor whiteColor];
    self.likeCount.font = font(14);
    [self.toolView addSubview:self.likeCount];

    [self.likeCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.toolView).offset(-16);
        make.right.equalTo(self.toolView.mas_right).offset(-16);
    }];
    self.likeIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_like_tag"]];
    self.likeIcon.highlightedImage = [UIImage imageNamed:@"home_detail_like_select_tag"];
    [self.toolView addSubview:self.likeIcon];
    [self.likeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.likeCount.mas_left).offset(-10);
    }];
    
    self.dissCount = [[UILabel alloc]init];
    self.dissCount.textColor = [UIColor whiteColor];
    self.dissCount.font = font(14);
    [self.toolView addSubview:self.dissCount];

    [self.dissCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.likeIcon.mas_left).offset(-18);
    }];
    self.dissIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_diss_tag"]];
    self.dissIcon.highlightedImage = [UIImage imageNamed:@"home_detail_diss_select_tag"];
    [self.toolView addSubview:self.dissIcon];
    [self.dissIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.dissCount);
        make.right.equalTo(self.dissCount.mas_left).offset(-10);
    }];
    self.commentCount = [[UILabel alloc]init];
    self.commentCount.textColor = [UIColor whiteColor];
    self.commentCount.font = font(14);
    [self.toolView addSubview:self.commentCount];
    [self.commentCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.dissIcon.mas_left).offset(-18);
    }];
    
    self.commentIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_detail_comment_tag"]];
    [self.toolView addSubview:self.commentIcon];
    [self.commentIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.likeCount);
        make.right.equalTo(self.commentCount.mas_left).offset(-10);
    }];
    
    self.likeBtn = [[UIButton alloc]init];
    [self.likeBtn addTarget:self action:@selector(likeMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.likeBtn];
 
    [self.likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.likeIcon.mas_bottom).offset(5);
        make.top.equalTo(self.likeIcon.mas_top).offset(-5);
        make.left.equalTo(self.likeIcon.mas_left);
        make.right.equalTo(self.likeCount.mas_right);
    }];
    [self.likeIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];
 
    self.dissBtn = [[UIButton alloc]init];
    [self.dissBtn addTarget:self action:@selector(dissMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.toolView addSubview:self.dissBtn];
 
    [self.dissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.dissIcon.mas_bottom).offset(5);
        make.top.equalTo(self.dissIcon.mas_top).offset(-5);
        make.left.equalTo(self.dissIcon.mas_left);
        make.right.equalTo(self.dissCount.mas_right);
    }];
    [self.dissIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];
 
    self.commentBtn = [[UIButton alloc]init];
    [self.commentBtn addTarget:self action:@selector(commentMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.commentBtn];
 
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.commentIcon.mas_bottom).offset(5);
        make.top.equalTo(self.commentIcon.mas_top).offset(-5);
        make.left.equalTo(self.commentIcon.mas_left);
        make.right.equalTo(self.commentCount.mas_right);
    }];
    
    
    self.tagView = [[UIView alloc]init];
    self.tagView.layer.cornerRadius = 11;
    self.tagView.layer.masksToBounds = YES;
    self.tagView.backgroundColor = RGBA(255, 255, 255, 0.5);
    [self.footerView addSubview:self.tagView];
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.bottom.equalTo(self.toolView.mas_top).offset(-12);
        make.height.mas_equalTo(22.0f);
    }];

    self.tagLb = [[UILabel alloc]init];
    self.tagLb.textColor = UIColor.whiteColor;
    self.tagLb.font = font(12);
    self.tagLb.text = @"话题";
    [self.tagView addSubview:self.tagLb];
    self.tagImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_page_#_tag"]];
    [self.tagView addSubview:self.tagImageView];

    [self.tagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tagView);
        make.left.equalTo(self.tagView).offset(12);
    }];
    
    [self.tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.tagView);
        make.left.equalTo(self.tagImageView.mas_right).offset(4);
        make.right.equalTo(self.tagView.mas_right).offset(-12);
    }];
    
    
    self.headerIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"defaut_header"]];
    self.headerIcon.layer.cornerRadius = 19;
    self.headerIcon.layer.masksToBounds = YES;
    [self.footerView addSubview:self.headerIcon];

    [self.headerIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.tagView.mas_top).offset(-12);
        make.left.equalTo(self.footerView).offset(16);
        make.size.mas_equalTo(CGSizeMake(38, 38));
    }];
    
    self.nameLb = [[UILabel alloc]init];
    self.nameLb.text = @"Charlene";
    self.nameLb.textColor = [UIColor whiteColor];
    self.nameLb.font = [UIFont boldSystemFontOfSize:14];
    [self.footerView addSubview:self.nameLb];
    
    
    self.subTitleLb = [[UILabel alloc]init];
    self.subTitleLb.textColor = RGBA(204, 204, 204, 1);
    self.subTitleLb.font = [UIFont boldSystemFontOfSize:14];
    self.subTitleLb.textAlignment = NSTextAlignmentLeft;
    self.subTitleLb.text = @"2019-12-12";
    [self.footerView addSubview:self.subTitleLb];
    
    self.followBtn = [[UIButton alloc]init];
    [self.followBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.followBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.followBtn.titleLabel.font = font(14);
    [self.followBtn setBackgroundImage:[UIImage imageNamed:@"social_confirm_tag"] forState:UIControlStateNormal];
    [self.followBtn setBackgroundImage:[UIImage imageNamed:@"social_confirm_tag"] forState:UIControlStateHighlighted];
    [self.followBtn addTarget:self action:@selector(followMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.footerView addSubview:self.followBtn];



    [self.followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.headerIcon.mas_bottom).offset(-6);
        make.right.equalTo(self.footerView).offset(-16);
        make.size.mas_equalTo(CGSizeMake(60, 26));
    }];
    
    [self.subTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLb);
        make.left.equalTo(self.nameLb.mas_right).offset(4);
        make.right.equalTo(self.followBtn.mas_left).offset(-12);
        make.width.mas_greaterThanOrEqualTo(60);
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIcon.mas_right).offset(8);
        make.centerY.equalTo(self.headerIcon);
        make.right.equalTo(self.subTitleLb.mas_left).offset(-4);
    }];
    
    self.footerView.hidden = YES;
    
    [self.commentIcon setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal | UILayoutConstraintAxisVertical];

    self.headerIcon.userInteractionEnabled = YES;
    UITapGestureRecognizer *userInfoTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfo)];
    [self.headerIcon addGestureRecognizer:userInfoTap];
    self.nameLb.userInteractionEnabled = YES;
    UITapGestureRecognizer *nameTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showUserInfo)];
    [self.nameLb addGestureRecognizer:nameTap];

    self.tagView.userInteractionEnabled = YES;
    UITapGestureRecognizer *topicTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showTopicList)];
    [self.tagView addGestureRecognizer:topicTap];
    
    
    
    [self.longPressFooterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView.mas_bottom);
        make.left.right.bottom.equalTo(self.contentView);
    }];
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(showMenuViewPress:)];
    
    UILongPressGestureRecognizer *longPress1 = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(showMenuViewPress:)];
    
    [self.longPressFooterView addGestureRecognizer:longPress1];
    
    [self.scrollView addGestureRecognizer:longPress];
    
    
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.colors = @[(id)RGBA(0, 0, 0, 0).CGColor,(id)RGBA(0, 0, 0, 0.5).CGColor,(id)RGBA(0, 0, 0,0.7).CGColor];
    [self.footerView.layer insertSublayer:self.gradientLayer atIndex:0];
    
    
}

- (void)showMenuViewPress:(UIGestureRecognizer *)gestureRecognizer{
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemLongPressToolView)]) {
            [self.delegate contentItemLongPressToolView];
        }
    }
}

- (void)setItemModel:(HomePageItemModel *)itemModel indexPath:(NSIndexPath *)indexPath{
    
    if (itemModel.contentText.length != 0) {
        self.scrollView.contentSize = CGSizeMake((kScreenW - 32) * itemModel.contentArray.count, 0);
        [self.scrollView.subviews enumerateObjectsUsingBlock:^(__kindof UILabel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.hidden = YES;
            if (idx < itemModel.contentArray.count) {
                obj.hidden = NO;
                obj.attributedText = itemModel.contentArray[idx];
            }
        }];
        [self.scrollView setContentOffset:CGPointMake(kScreenW * itemModel.currentIndex, 0) animated:YES];
    }
    
    
    self.likeIcon.highlighted = itemModel.isLike;
    self.dissIcon.highlighted = itemModel.isUnLike;

    
    self.footerView.hidden = !itemModel.showFooterTool;
    self.gradientLayer.hidden = !itemModel.showFooterTool;
    
    self.currentModel = itemModel;

    CGFloat isTagHeight = 0;
    
    
    if (!itemModel.showUserInfo) {
        self.headerIcon.hidden = YES;
        self.nameLb.text = @"";
        [self.headerIcon mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(0);
            make.left.equalTo(self.contentView);
        }];
        [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headerIcon.mas_right).offset(10);
        }];
    }else{
        self.headerIcon.hidden = NO;
        self.nameLb.text = itemModel.realName;
        [self.headerIcon mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(38);
            make.left.equalTo(self.contentView).offset(16);
        }];
        [self.nameLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.headerIcon.mas_right).offset(8);
        }];
    }
    
    if (itemModel.showUserInfo) {
        self.subTitleLb.text = itemModel.showCreateTime?[NSString stringWithFormat:@"· %@",itemModel.createDetailTimeStr]:@"";
    }else{
        self.subTitleLb.text = itemModel.showCreateTime?[NSString stringWithFormat:@"%@",itemModel.createDetailTimeStr]:@"";
       
    }
    
    CGSize size = [RPAppManager getTextSizeWithText:self.subTitleLb.text font:[UIFont boldSystemFontOfSize:14] maxSize:CGSizeMake(kScreenW, MAXFLOAT)];
    
    [self.subTitleLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_greaterThanOrEqualTo(ceil(size.width));
    }];
    

//    // 判断是否是作品
    if (![itemModel.type isEqualToString:@"2"] && itemModel.tag != nil) {
        self.tagLb.text = itemModel.tag.tagName;
        self.tagView.hidden = NO;
        [self.tagView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(22);
        }];
        isTagHeight = 0;
    }else{
        self.tagLb.text = @"";
        self.tagView.hidden = YES;
        [self.tagView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
        isTagHeight = -22;
    }
    self.maxHeight = TOOLHEIGHT + TAGHEIGHT + HEADERHEIGHT + GK_SAVEAREA_BTM + isTagHeight;
    if (self.currentModel.showFooterTool) {
        self.footerView.hidden = NO;
        [self.footerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(self.maxHeight);
        }];
    }else{
        self.footerView.hidden = YES;
        [self.footerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(self.maxHeight);
            make.height.mas_equalTo(self.maxHeight);
        }];
    }


    if (itemModel.likeNum.intValue >= 10000) {
        NSInteger count = itemModel.likeNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.likeCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.likeCount.text = [NSString stringWithFormat:@"%@",itemModel.likeNum];
    }
    
    if (itemModel.unlikeNum.intValue >= 10000) {
        NSInteger count = itemModel.unlikeNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.dissCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.dissCount.text = [NSString stringWithFormat:@"%@",itemModel.unlikeNum];
    }
    
    
    
    if (itemModel.commentNum.intValue >= 10000) {
        NSInteger count = itemModel.commentNum.intValue;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.commentCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.commentCount.text = [NSString stringWithFormat:@"%@",itemModel.commentNum.intValue==0?@0:itemModel.commentNum];
    }
    
    if (itemModel.showUserInfo) {
        if ([RPAppManager getCustomerId] && [itemModel.userId isEqualToNumber:[RPAppManager getCustomerId]]) {
            self.followBtn.hidden = YES;
        }else{
            if (itemModel.followType.intValue == 3 || itemModel.followType.intValue == 1) {
                self.followBtn.hidden = YES;
            }else if (itemModel.followType.intValue == 2){
                self.followBtn.hidden = NO;
                [self.followBtn setTitle:@"+ 回关" forState:UIControlStateNormal];
            }else{
                self.followBtn.hidden = NO;
                [self.followBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
            }
        }
    }else{
        self.followBtn.hidden = YES;
    }
    
    if ([itemModel.userId isEqualToNumber:[RPAppManager getCustomerId]]) {
        UserInfoModel *userInfo = [UserInfoModel userInfo];
        if (userInfo.imagePath.length == 0) {
            if (userInfo.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (userInfo.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:userInfo.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }
    }else{
        if (itemModel.imagePath.length == 0) {
            if (itemModel.sex.intValue == 0) {
                self.headerIcon.image = [UIImage imageNamed:@"defaut_header"];
            }else if (itemModel.sex.intValue == 1){
                self.headerIcon.image = [UIImage imageNamed:@"common_boy_tag"];
            }else{
                self.headerIcon.image = [UIImage imageNamed:@"common_girl_tag"];
            }
        }else{
            [self.headerIcon sd_setImageWithURL:[NSURL URLWithString:itemModel.imagePath] placeholderImage:[UIImage imageNamed:@"defaut_header"]];
        }

    }
        
    if ([[RPAppManager getCustomerId] isEqualToNumber:itemModel.userId]) {
        // 审核中 或者 已拒绝
        self.likeBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
//        self.shareBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
        self.dissBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
        self.commentBtn.userInteractionEnabled = itemModel.isDisplay.intValue == 1;
//        self.shareIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_share_tag":@"home_unshare_tag"];
        self.likeIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_like_tag":@"home_unlike_tag"];
        self.dissIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_diss_tag":@"home_undiss_tag"];
        self.commentIcon.image = [UIImage imageNamed:itemModel.isDisplay.intValue == 1?@"home_detail_comment_tag":@"home_uncomment_tag"];
        
        self.commentCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
//        self.shareCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        self.dissCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        self.likeCount.textColor = itemModel.isDisplay.intValue == 1?UIColor.whiteColor:C102;
        
    }else{
        self.likeBtn.userInteractionEnabled = YES;
//        self.shareBtn.userInteractionEnabled = YES;
        self.dissBtn.userInteractionEnabled = YES;
        self.commentBtn.userInteractionEnabled = YES;
        
//        self.shareIcon.image = [UIImage imageNamed:@"home_detail_share_tag"];
        self.likeIcon.image = [UIImage imageNamed:@"home_detail_like_tag"];
        self.dissIcon.image = [UIImage imageNamed:@"home_detail_diss_tag"];
        self.commentIcon.image = [UIImage imageNamed:@"home_detail_comment_tag"];
        
        self.commentCount.textColor = UIColor.whiteColor;
//        self.shareCount.textColor = UIColor.whiteColor;
        self.dissCount.textColor = UIColor.whiteColor;
        self.likeCount.textColor = UIColor.whiteColor;
    }
    
    
    
    
}


- (NSArray *)coreTextPaging:(NSAttributedString *)str textFrame:(CGRect)textFrame{
    NSMutableArray *pagingResult = [NSMutableArray array];
    CFAttributedStringRef cfAttStr = (__bridge CFAttributedStringRef)str;
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(cfAttStr);
    CGPathRef path = CGPathCreateWithRect(textFrame, NULL);

    int textPos = 0;
    NSUInteger strLength = [str length];
    while (textPos < strLength)  {
        //设置路径
        CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(textPos, 0), path, NULL);
        //生成frame
        CFRange frameRange = CTFrameGetVisibleStringRange(frame);
        NSRange ra = NSMakeRange(frameRange.location, frameRange.length);

       //获取范围并转换为NSRange，然后以NSAttributedString形式保存
        [pagingResult addObject:[str attributedSubstringFromRange:ra]];
        
        //移动当前文本位置
        textPos += frameRange.length;
       
        CFRelease(frame);
    }
    CGPathRelease(path);
    CFRelease(framesetter);
    return pagingResult;
}

- (void)coverMethod{
    self.currentModel.showFooterTool = !self.currentModel.showFooterTool;
    CGFloat offset = self.currentModel.showFooterTool?0:self.maxHeight;

    [UIView animateWithDuration:0.25 animations:^{
        [self.footerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(offset);
        }];
        [self.contentView layoutIfNeeded];
    } completion:^(BOOL finished) {
        if (finished) {
            self.footerView.hidden = !self.currentModel.showFooterTool;
            self.gradientLayer.hidden = !self.currentModel.showFooterTool;
        }
    }];
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemShowHideToolView)]) {
        [self.delegate contentItemShowHideToolView];
    }
}

- (void)likeMethod{
    
    if ([RPAppManager isShowNetworkView]) {
        [WHToast showErrorWithMessage:@"网络好像有点问题，请检查后重试" duration:2 finishHandler:nil];
        return;
    }
    
    self.currentModel.isLike = !self.currentModel.isLike;
    
    self.likeIcon.highlighted = self.currentModel.isLike;
    
    NSInteger max = self.currentModel.likeNum.intValue +  (self.currentModel.isLike?1:-1);
    
    if (max >= 10000) {
        NSInteger count = max;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.likeCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.likeCount.text = [NSString stringWithFormat:@"%ld",(long)max];
    }
    
    
    self.currentModel.likeNum = @(max);
    
    
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemLikeWithCurrentModel:)]) {
        [self.delegate contentItemLikeWithCurrentModel:self.currentModel];
    }
}
- (void)dissMethod{
    
    
    if ([RPAppManager isShowNetworkView]) {
        [WHToast showErrorWithMessage:@"网络好像有点问题，请检查后重试" duration:2 finishHandler:nil];
        return;
    }
    
    self.currentModel.isUnLike = !self.currentModel.isUnLike;
    
    self.dissIcon.highlighted = self.currentModel.isUnLike;
    
    NSInteger max = self.currentModel.unlikeNum.intValue + (self.currentModel.isUnLike?1:-1);
    
    if (max >= 10000) {
        NSInteger count = max;
        if (count % 1000 == 0) {
            count += 1;
        }
        self.dissCount.text = [NSString stringWithFormat:@"%@w",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.dissCount.text = [NSString stringWithFormat:@"%ld",(long)max];
    }
    
    self.currentModel.unlikeNum = @(max);
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemDissWithCurrentModel:)]) {
        [self.delegate contentItemDissWithCurrentModel:self.currentModel];
    }
}
- (void)shareMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemShareInfoWithCurrentModel:)]) {
        [self.delegate contentItemShareInfoWithCurrentModel:self.currentModel];
    }
}
- (void)commentMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemCommentInfoWithCurrentModel:)]) {
        [self.delegate contentItemCommentInfoWithCurrentModel:self.currentModel];
    }
}

- (void)followMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemFollowWithCurrentModel:)]) {
        [self.delegate contentItemFollowWithCurrentModel:self.currentModel];
    }
}
- (void)showUserInfo{
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemShowUserInfoWithCurrentModel:)]) {
        [self.delegate contentItemShowUserInfoWithCurrentModel:self.currentModel];
    }
}

- (void)showTopicList{
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemTopicListWithCurrentTopicModel:)]) {
        [self.delegate contentItemTopicListWithCurrentTopicModel:self.currentModel.tag];
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"HomePageContentDetailCell";
    HomePageContentDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[HomePageContentDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];

    
    if (!self.currentModel.showUserInfo && self.currentModel.showCreateTime) {
        self.gradientLayer.frame = CGRectMake(0, self.subTitleLb.cl_y, kScreenW,self.footerView.cl_height - self.subTitleLb.cl_y);
    }else{
        self.gradientLayer.frame = CGRectMake(0, 0, kScreenW, self.footerView.cl_height);
    }
}

#pragma mark - XHPageControlDelegate
-(void)xh_PageControlClick:(XHPageControl*)pageControl index:(NSInteger)clickIndex{
    [self.scrollView setContentOffset:CGPointMake((kScreenW - 32)* clickIndex, 0) animated:YES];
}
#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    NSInteger index = scrollView.contentOffset.x/(kScreenW - 32);
    self.currentModel.currentIndex = index;
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentItemSelectAtIndex:)]) {
        [self.delegate contentItemSelectAtIndex:self.currentModel.currentIndex];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    
    NSInteger index = scrollView.contentOffset.x/(kScreenW - 32);
    if (scrollView.contentOffset.x <= 0) {
        [WHToast showMessage:@"已是第一页" duration:2 finishHandler:nil];
    }
    
    if (index == self.currentModel.contentArray.count - 1) {
        [WHToast showMessage:@"没有更多了" duration:2 finishHandler:nil];
    }
}

@end
